
#include <stdio.h>
#include "FreeRTOS.h"
#include "app_task.h"
#include "semphr.h"
#include "test.h"

TaskHandle_t AppTaskCreate_Handle = NULL;
TaskHandle_t LEDTaskCreate_Handle = NULL;
TaskHandle_t PrintTaskCreate_Handle = NULL;
SemaphoreHandle_t CountSem_Handle = NULL;

void Task_LED_Entry(void)
{
	BaseType_t xRerun = pdTRUE;
	while (1)
	{
		xRerun = xSemaphoreTake(CountSem_Handle,1000);
		if(pdTRUE == xRerun)
		{
			test();
			xSemaphoreGive(CountSem_Handle);
		}
		vTaskDelay(500);
	}
}

void Task_Print_Entry(void)
{
	BaseType_t xRerun = pdTRUE; 
	while(1)
	{
		xRerun = xSemaphoreTake(CountSem_Handle,1000);
		if(pdTRUE == xRerun)
		{
			xSemaphoreGive(CountSem_Handle);
		}
		vTaskDelay(500);
	}
}  

void AppTaskCreate(void)
{
	BaseType_t xReturn = pdPASS;																																													
	taskENTER_CRITICAL();																																													
																																													
	CountSem_Handle = xSemaphoreCreateCounting(1,1);																																													
																																													
	if(NULL != CountSem_Handle)																																													
	{																																													
		//printf("\nSemapore Create Err \r\n");																																													
	} 																																													
	xReturn = xTaskCreate((TaskFunction_t)Task_LED_Entry, (const char *)"LED_Task" , (uint16_t)128,(void*)NULL,(BaseType_t)2,(TaskHandle_t*)&LEDTaskCreate_Handle);
	xReturn = xTaskCreate((TaskFunction_t)Task_Print_Entry,(const char *)"Print_Task" , (uint16_t)128,(void*)NULL,(BaseType_t)3,(TaskHandle_t*)&PrintTaskCreate_Handle);
	if(pdPASS == xReturn)																																													
	{																																													
		//printf("\nCreate Task is ok \r\n");																																													
	}																																													
	vTaskDelete(AppTaskCreate_Handle);     																																													
	taskEXIT_CRITICAL();																																													
}
